/**
 * 文件名：****.java
 * 版权：Copyright Lightkit All Rights Reserved.
 * 描述：*****
 */
package com.lightkits.wms.domain.mainpage;

import com.lightkits.framework.common.utility.object.ObjectUtil;
import com.lightkits.framework.soa.hzero.executor.ServiceExecutor;
import com.lightkits.wms.domain.mainpage.service.WareHouseInfoDomainService;
import com.lightkits.wms.dto.mainpage.QueryWareHouseRequestType;
import com.lightkits.wms.dto.mainpage.QueryWareHouseResponseType;
import com.lightkits.wms.dto.mainpage.model.WareHouseInfoDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class QueryWareHouseInfoExecutor implements
        ServiceExecutor<QueryWareHouseRequestType, QueryWareHouseResponseType> {
    private final WareHouseInfoDomainService service;

    @Autowired
    public QueryWareHouseInfoExecutor(WareHouseInfoDomainService service) {
        this.service = service;
    }

    @Override
    public QueryWareHouseResponseType service(QueryWareHouseRequestType request) {
        QueryWareHouseResponseType response = new QueryWareHouseResponseType();
        response.setSuccessful(true);
        String warehouseCode = request.getWarehouseCode();
        String organizationId = request.getOrganizationId();
        List<WareHouseInfoDTO> wareHouseInfoDTOList = service.listWareHouseInfo(warehouseCode,
                organizationId,
                request.getCategroySet(),
                request.getWmAreaFlag());
        if (!ObjectUtil.isNullOrEmpty(wareHouseInfoDTOList)) {
            response.setPageDataCount(wareHouseInfoDTOList.size());
        }
        response.setWareHouseInfoDTOList(wareHouseInfoDTOList);
        return response;
    }
}
